package com.yang.dao.impl;

import com.yang.dao.TimeSchedulerDao;
import com.yang.entity.OrderFormEntity;
import com.yang.entity.RelationEntity;
import com.yang.entity.RoomEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.orm.hibernate4.HibernateTemplate;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Transactional
@Repository
public class TimeSchedulerDaoImpl implements TimeSchedulerDao {

    @Autowired
    HibernateTemplate hibernateTemplate;
    @Override
    public List<OrderFormEntity> selectAllOrder() {
        String hql = "FROM OrderFormEntity";
        List<OrderFormEntity> orderFormEntities = (List<OrderFormEntity>) hibernateTemplate.find(hql);
        return orderFormEntities;
    }

    @Override
    public List<RelationEntity> selectRelationByOrderId(String status) {
        String hql = "FROM RelationEntity WHERE status = ?";
        List<RelationEntity> relationEntities = (List<RelationEntity>) hibernateTemplate.find(hql,status);
        return relationEntities;
    }

    @Override
    public void updateRelation(RelationEntity relationEntity) {
        hibernateTemplate.update(relationEntity);
    }

    @Override
    public void updateRoom(RoomEntity roomEntity) {
        hibernateTemplate.update(roomEntity);
    }
}
